/*
 * DoublyLinkedList.h
 *
 *  Created on: 2012-04-04
 *      Author: tony
 */

#ifndef DOUBLYLINKEDLIST_H_
#define DOUBLYLINKEDLIST_H_

#include <iostream>

namespace graph {

class DoublyLinkedList {
public:
	DoublyLinkedList();
	virtual ~DoublyLinkedList();
	void addEdge( const int i, const int j, const float w );
	void removeEdge( const int i, const int j );
	// insertion operator
	friend std::ostream& operator <<(std::ostream& out, const DoublyLinkedList& d) {
		DLNode* p = d.first;
		while (p != NULL){
			out << "--> " << *p;
			p = p->getNext();
		}
		return out;
	}

private:
	/*
	 * Data member
	 */
	class DLNode;
	DLNode* first;

	/*
	 * Inner doubly-linked node class
	 */
	class DLNode{
	public:
		DLNode(const int s, const int e, const float w, DLNode* n, DLNode* p):
			start(s), end(e), edgeweight(w), next(n), prev(p) {
			std::cout << "          DLNode constructor - " << std::endl;
		}
		virtual ~DLNode(){
			std::cout << "          DLNode destructor" << std::endl;
		}
		// getters, setters
		int getEnd()const { return end; }
		DLNode* getNext()const { return next; }
		DLNode* getPrev()const { return prev; }
		void setNext(DLNode* n){ next = n; }
		void setPrev(DLNode* p){ prev = p; }

		// insertion operator
		friend std::ostream& operator <<(std::ostream& out, const DLNode& n) {
			out << "[ " << n.end << ", " << n.edgeweight << " ]";
			return out;
		}
	private:
		int start;
		int end;
		float edgeweight;
		DLNode* next;
		DLNode* prev;
	};
};

} /* namespace graph */
#endif /* DOUBLYLINKEDLIST_H_ */
